package plus.easydo.starter.oauth.client.configure;

import org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
import plus.easydo.starter.oauth.client.service.CustomizeClientServer;
import plus.easydo.starter.oauth.core.config.SecurityBeanConfig;

import javax.annotation.Resource;

/**
 * @author laoyu
 * @version 1.0
 */
@Configuration("clientBeanConfig")
@EnableConfigurationProperties({OAuth2ClientProperties.class})
public class ClientBeanConfig implements SecurityBeanConfig<OAuth2ClientProperties> {


    @Resource
    OAuth2ClientProperties oAuth2ClientProperties;


    @Override
    public OAuth2ClientProperties properties() {
        return oAuth2ClientProperties;
    }


    @Override
    public ClientDetailsService getClientDetailsService() {
        return null;
    }

    @Override
    public AuthorizationServerTokenServices getAuthorizationServerTokenServices() {
        return null;
    }

    @ConfigurationProperties(prefix = "security.oauth2.client")
    @Bean
    public ClientCredentialsResourceDetails clientCredentialsResourceDetails() {
        return new ClientCredentialsResourceDetails();
    }

    @Bean
    public CustomizeClientServer customizeClientServer(OAuth2ProtectedResourceDetails clientCredentialsResourceDetails) {
        return new CustomizeClientServer(clientCredentialsResourceDetails);
    }

}
